package com.zdkj.common.core.exceltools;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @ProjectName: zdkj
 * @Package: com.zdkj.subway.st.exceltools
 * @ClassName: ExcelVersion
 * @Description:
 * @Author: kangjian
 * @CreateDate: 2020/1/13 9:13
 * @Version: 1.0
 */
@AllArgsConstructor
@Getter
public enum ExcelVersion {
    /**
     *03版本
     */
    XLS("2003", ".xls"),
    /**
     *03版本
     */
    XLSX("2007", ".xlsx"),
    /**
     *未知版本
     */
    UNKNOWN("unknown","未知");


    private String version;
    private String fileSuffix;

    /**
     * 根据Key得到枚举的Value
     * Lambda表达式，比较判断（JDK 1.8）
     *
     * @param key
     * @return
     */
    public static ExcelVersion getEnumType(String key) {
        return Arrays.asList(ExcelVersion.values()).stream()
                .filter(excelVersion -> excelVersion.getVersion().equals(key))
                .findFirst().orElse(ExcelVersion.UNKNOWN);
    }
}
